module.exports = request

const baseUrl = 'https://help.iava.top/'
let ajaxTimes = 0; // 处理数据请求的总数，用来控制loading图标
/** 
 * 处理数据请求的接口
 */
function request(params) {
	ajaxTimes++
	uni.showLoading({
		title: '加载中',
		mask: true
	})
	return new Promise((resolve, reject) => {
		uni.request({
			...params,
			url: baseUrl + params.url,
			dataType: 'json',
			header: {
				// "accept": "*/*",
				"conent-type": "application/json;charset=utf-8",
				'token':uni.getStorageSync('token')
			},
			success: (result) => {
				resolve(result)
			},
			fail: (err) => {
				reject(err)
			},
			complete: () => {
				ajaxTimes--
				if (ajaxTimes === 0) {
					uni.hideLoading()
				}
			}
		})
	})
}
